package com.stefan.lession05;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class ButtonDemo01 extends JFrame {

    public ButtonDemo01(){
        Container container = this.getContentPane();

        // 将图片变为图标
        URL url = ButtonDemo01.class.getResource("test.jpg");
        ImageIcon imageIcon = new ImageIcon(url);

        // 把图标放在按钮上
        JButton jButton = new JButton();
        jButton.setSize(20,20);
        jButton.setIcon(imageIcon);
        jButton.setToolTipText("图标按钮");

        container.add(jButton);

        this.setVisible(true);
        this.setSize(500,300);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new ButtonDemo01();
    }
}
